import java.util.HashMap;
import java.util.Map;

/**
 * @author LKQ
 * @date 2022/3/6 14:28
 * @description
 */
public class Solution {
    public static void main(String[] args) {

    }
    public TreeNode createBinaryTree(int[][] descriptions) {
        Map<Integer, TreeNode> map = new HashMap<>();
        int[] visited = new int[100001];
        for (int[] des: descriptions) {
            if (!map.containsKey(des[0])) {
                TreeNode node = new TreeNode(des[0]);
                map.put(des[0], node);
            }
            if (!map.containsKey(des[1])) {
                TreeNode node = new TreeNode(des[1]);
                map.put(des[1], node);
            }
            // 建立关系
            TreeNode root = map.get(des[0]);
            TreeNode child = map.get(des[1]);
            // 如果该节点是儿子节点，记录下来
            visited[des[1]] = 1;
            if (des[2] == 1){
                root.left = child;
            }else {
                root.right = child;
            }
        }
        TreeNode head = new TreeNode();
        for(Integer i: map.keySet()) {
            if (visited[i] == 0) {
                head = map.get(i);
                return head;
            }
        }
        return head;
    }
}
